package controllers

import (
	"encoding/json"

	"github.com/gin-gonic/gin"
	"github.com/hibiken/asynq"
	"pets.ser163.cn/config"
)

func GetQueue(c *gin.Context) {

	payload := map[string]interface{}{
		"user_id": 42,
	}

	// Marshal the payload to a []byte
	payloadBytes, err := json.Marshal(payload)
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
		return
	}

	task := asynq.NewTask("send_email", payloadBytes)
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
		return
	}
	info, err := config.Asynq.Enqueue(task)
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
		return
	}
	c.JSON(200, gin.H{"status": "Enqueued", "task_id": info.ID})
}
